import datetime
import time

def local2utc(local_date,utc_format='%Y-%m-%dT%H:%M:%S.%fZ'):
    """
    本地时间转UTC
    param date
    return str
    """
    now_stamp = time.time()
    local_time = datetime.datetime.fromtimestamp(now_stamp)
    utc_time = datetime.datetime.utcfromtimestamp(now_stamp)
    offset = local_time - utc_time
    utc_dt = local_date - offset
    return utc_dt.strftime(utc_format)

def utc2local(utc_str,local_format = '%Y-%m-%d %H:%M:%S'):
    """
    UTC时间转本地时间（+8:00）
    param str
    return str
    """
    utc_date = datetime.datetime.strptime(utc_str, '%Y-%m-%dT%H:%M:%S.%fZ')

    now_stamp = time.time()
    local_time = datetime.datetime.fromtimestamp(now_stamp)
    utc_time = datetime.datetime.utcfromtimestamp(now_stamp)
    offset = local_time - utc_time
    local_st = utc_date + offset
    return local_st.strftime(local_format)
